import { Item, Task } from '@/types/list'
import { loginParams, LoginResponse } from '@/types/login'
import { updateTodoParams } from '@/types/todo'
import http from '.'

export async function login(params: loginParams) {
	return http.post<LoginResponse>('/api/user/auth', {
		username: params.username,
		password: params.password,
		grantType: 'password'
	})
}

export async function getList(uid: string) {
	return http.get<Item[]>(`/api/List/${uid}`)
}

export async function addList(params: {
	title: string
	icon: string
	userId: string
}) {
	return http.post('/api/List', params)
}

export async function alertTodoTitle(params: {
	id: string | undefined
	title: string
	icon?: string
}) {
	return http.put('/api/List/title', params)
}

export async function delList(id: string) {
	return http.delete(`/api/List/${id}`)
}

export async function addTask(params: { listId: string; todo: string }) {
	return http.post<Task>('/api/Task', params)
}

export async function updateTask(params: updateTodoParams) {
	return http.put('/api/Task', params)
}

export async function deleteTask({
	lid,
	index
}: {
	lid: string
	index: number
}) {
	return http.delete(`/api/Task/${lid}/${index}`)
}
